package com.bawei.weekone2207a.view

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bawei.weekone2207a.R
import com.bawei.weekone2207a.route.RouteConfig
import kotlinx.coroutines.delay

/**
 * 作者：赵亮
 * 时间：2024/12/14 9:42
 * 功能：
 */
@Composable
fun StartPage(navController: NavController = rememberNavController()) {

    var second by remember {
        mutableStateOf(3)
    }

    LaunchedEffect(key1 = "") {
        while(second > 0) {
            second --
            delay(1000)
        }
        // 跳转到引导页
        navController.navigate(RouteConfig.GUIDE)
    }

    Box (modifier = Modifier.fillMaxSize()){
        Image(
            contentScale = ContentScale.Crop,
            modifier = Modifier.fillMaxSize(),
            painter = painterResource(
                id = R.drawable.start
            ), contentDescription = null
        )
        Text(text = "跳过${second}S", modifier = Modifier
            .align(Alignment.TopEnd)
            .padding(top = 30.dp, end = 10.dp))
    }

}

@Preview(showSystemUi = true)
@Composable
fun StartPagePreview() {
    StartPage()
}

